﻿using System;
using System.Collections.Generic;

namespace SharpSqlAnalyzer.util
{
	// Token: 0x02000079 RID: 121
	internal class keywordListFactory
	{
		// Token: 0x17000043 RID: 67
		// (get) Token: 0x060002E8 RID: 744 RVA: 0x002F8E51 File Offset: 0x002F7051
		public static keywordListFactory Instance
		{
			get
			{
				return keywordListFactory.SingletonContainer.instance;
			}
		}

		// Token: 0x060002E9 RID: 745 RVA: 0x002F8E58 File Offset: 0x002F7058
		public virtual keywordList getDbKeywordList(EDbVendor dbvendor, string dbVersion)
		{
			this.loadDbKeywordList(dbvendor);
			keywordMap keywordMap = this.dbKeywordListMap[dbvendor];
			if (keywordMap != null)
			{
				return keywordMap.getDbKeywordList(dbVersion);
			}
			return null;
		}

		// Token: 0x060002EA RID: 746 RVA: 0x002F8E88 File Offset: 0x002F7088
		public virtual List<string> getAvailableDbVersions(EDbVendor dbvendor)
		{
			this.loadDbKeywordList(dbvendor);
			keywordMap keywordMap = this.dbKeywordListMap[dbvendor];
			if (keywordMap != null)
			{
				return keywordMap.DbVersions;
			}
			return null;
		}

		// Token: 0x060002EB RID: 747 RVA: 0x002F8EB4 File Offset: 0x002F70B4
		public virtual bool containsDbVersion(EDbVendor dbvendor, string dbVersion)
		{
			this.loadDbKeywordList(dbvendor);
			keywordMap keywordMap = this.dbKeywordListMap[dbvendor];
			return keywordMap != null && dbVersion != null && keywordMap.containsVersion(dbVersion);
		}

		// Token: 0x060002EC RID: 748 RVA: 0x002F8EE4 File Offset: 0x002F70E4
		protected internal virtual void loadDbKeywordList(EDbVendor dbvendor)
		{
			if (this.dbKeywordListMap.ContainsKey(dbvendor))
			{
				return;
			}
			object obj = this.@object;
			lock (obj)
			{
				if (!this.dbKeywordListMap.ContainsKey(dbvendor))
				{
					keywordMap keywordMap = new keywordMap();
					this.dbKeywordListMap[dbvendor] = keywordMap;
					IDictionary<string, string> keywordList = keywordLoader.getKeywordList(dbvendor);
					if (keywordList != null)
					{
						string[] array = new List<string>(keywordList.Keys).ToArray();
						List<string> list = new List<string>();
						foreach (string text in array)
						{
							int num = text.IndexOf('_');
							if (num != -1)
							{
								string item = text.Substring(0, num).ToUpper();
								if (!list.Contains(item))
								{
									list.Add(item);
								}
							}
						}
						foreach (string text2 in list)
						{
							keywordList keywordList2 = new keywordList(dbvendor);
							string key = text2 + "_reserved";
							if (keywordList.ContainsKey(key))
							{
								string[] array2 = keywordList[key].Split(new char[]
								{
									','
								});
								for (int j = 0; j < array2.Length; j++)
								{
									string item2 = array2[j].Trim().ToUpper();
									if (!keywordList2.ReservedList.Contains(item2))
									{
										keywordList2.ReservedList.Add(item2);
									}
								}
								keywordList2.ReservedList.Sort();
							}
							string key2 = text2 + "_all";
							if (keywordList.ContainsKey(key2))
							{
								string[] array3 = keywordList[key2].Split(new char[]
								{
									','
								});
								for (int k = 0; k < array3.Length; k++)
								{
									string item3 = array3[k].Trim().ToUpper();
									if (!keywordList2.KeywordList.Contains(item3))
									{
										keywordList2.KeywordList.Add(item3);
									}
								}
								keywordList2.KeywordList.Sort();
							}
							else
							{
								keywordList2.KeywordList.AddRange(keywordList2.ReservedList);
							}
							keywordMap.setDbKeywordList(text2, keywordList2);
						}
					}
				}
			}
		}

		// Token: 0x060002ED RID: 749 RVA: 0x002F9148 File Offset: 0x002F7348
		private keywordListFactory()
		{
		}

		// Token: 0x0400108B RID: 4235
		private Dictionary<EDbVendor, keywordMap> dbKeywordListMap = new Dictionary<EDbVendor, keywordMap>();

		// Token: 0x0400108C RID: 4236
		private object @object = new object();

		// Token: 0x02000436 RID: 1078
		private class SingletonContainer
		{
			// Token: 0x04001EC6 RID: 7878
			internal static readonly keywordListFactory instance = new keywordListFactory();
		}
	}
}
